package function

import com.sun.javafx.image.impl.ByteIndexed.ToByteBgraAnyConverter

class Scala_Match {

  def fun(x:Any):Any=x match {
    /**
     * 匹配常量值
     */
    case 0=>"零"
    case "新增"=>"+"
    case "支出"=> "-"
  }
  def fun1(x:Any):Any=x match{
    /**
     * 匹配数据类型
     */
    case str:String=>"String"
    case int:Int=>"Int"
    case _=>"other type"
  }
  def fun2(array:Array[Any]):Any= for(arr<-array) {
    arr match{
      /**
       * 匹配数组
       */
      case Array(0)=>"0"
      case Array(i,j)=>s"匹配两个元素的数组：+i+${i}-${j}"
      case Array(0,_*)=>"第一元素为零的数组"
      case _=>"其他数组"
    }
    arr
  }


}
object Scala_Match{
  /**
   * 模式匹配：
   * @param args
   */
  def main(args: Array[String]): Unit = {
    val name:String="张三"
    val res=name match {
      case "李四"=>"员工"
      case "张三"=>"老板"
      case ""=>"其他"
    }
    println(res)
    val scala_Match = new Scala_Match()
    val fun= scala_Match.fun(0)
    println(fun.getClass.getSimpleName)
    println(fun)
    val fun1=scala_Match.fun1("List(1,2,3)")
    println(fun1)
//    val array = Array(Array(0), Array(0, 1), Array(0, 1, 2), Array(88, 123))
    val fun2=scala_Match.fun2(Array(Array(0), Array(0, 1), Array(0, 1, 2), Array(88, 123)))
    println(fun2)
    

  }
}
